﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Cherry.Agile.Scheduler.Host
{
    static class Unity
    {
        static string _appName;
        public static string AppName
        {
            get
            {
                if (_appName == null)
                {
                    var path = typeof(Unity).Assembly.Location;

                    if (File.Exists(path))
                    {
                        var cfg = System.Configuration.ConfigurationManager.OpenExeConfiguration(path);
                        _appName = cfg.AppSettings.Settings["service.name"].Value;
                    }
                    else
                        _appName = System.Configuration.ConfigurationManager.AppSettings.Get("service.name");
                    if (string.IsNullOrEmpty(_appName))
                        throw new ArgumentNullException("invalid config setting ,could not found service.name setting in the config file.");
                }
                return _appName;
            }
        }
    }
}
